<?php
require_once '../classes/ConnectionDB.php';
require_once '../classes/ClasseDataManager.php';
$codice = $_COOKIE['codiceUtente'];
$connection =ConnectionDB::getInstance()->connectToDB();
$studente = ClasseDataManager::getInstance()->getStudenteByCodice($connection, $codice);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <style>
            #resultProfile
            {
                font-size: 12px;
}
            
        </style>
        <script type="text/javascript">
               function xXMLHttpRequest()
        {

            var client = null;
            if (window.XMLHttpRequest)
            {
                client=new XMLHttpRequest();
            }
            // code for IE
            else if (window.ActiveXObject)
            {
                client=new ActiveXObject("Microsoft.XMLHTTP");
            }

            return client;
        }



        function modifica()
        {
            var client = xXMLHttpRequest();
            client.onreadystatechange = function()
            {
                if(this.readyState == 4 && this.status == 200)
                {

                    document.getElementById('result').style.visibility='visible';


                } else if (this.readyState == 4 && this.status != 200) {
                    // fetched the wrong page or network error...
                    alert("error this.status : " + this.status );

                }
            }
            var nome = document.getElementById('nome').value;
            var cognome = document.getElementById('cognome').value;
            var email =document.getElementById('email').value;
            var username =document.getElementById('username').value;
            var password =document.getElementById('password').value;

            var param = "operation=updateStudente&codice=<?= $_COOKIE["codiceUtente"]?>" +
                "&nome="+nome+
                "&cognome="+cognome+
                "&email="+email+
                "&username="+username+
                "&password="+password;
            client.open("POST", "../utente/nuovoOperatoreListener.php", true);
            client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

            client.send(param);

        }
    </script>
    </head>
    <body>
        <br /><br /><br />
        <center>
            <div id="resultProfile">
                <input type="hidden" id="nome" value="<?= $studente->getNome()?>" />
                <input type="hidden" id="cognome" value="<?= $studente->getCognome()?>" />
                <table cellpadding="10" cellspacing="10">
                    <tr>
                        <th style="color:white; text-align: left" >Codice : </th>
                        <td style="color:white"><?= $_COOKIE["codiceUtente"]?></td>
                    </tr>
                    <tr>
                        <th style="color:white; text-align: left" >Data creazione : </th>
                        <td style="color:white"><?= $studente->getDataCreazione() ?></td>
                    </tr>
                    <tr>
                        <th style="color:white; text-align: left">Nome : </th>
                        <td style="color:white"><?= $studente->getNome()?></td>
                    </tr>
                    <tr>
                        <th style="color:white; text-align: left">Cognome : </th>
                        <td style="color:white"><?= $studente->getCognome()?></td>
                    </tr>
                    <tr>
                        <th style="color:white; text-align: left">Email : </th>
                        <td style="color:white"><input type="text" id="email" name="email" value="<?= $studente->getEmail()?>"/></td>
                    </tr>
                    <tr>
                        <th style="color:white; text-align: left">Username : </th>
                        <td style="color:white"><input type="text" id="username" name="username" value="<?= $studente->getUsername()?>"/></td>
                    </tr>
                    <tr>
                        <th style="color:white; text-align: left">Password : </th>
                        <td style="color:white"><input type="password" id="password" name="password" value="<?= $studente->getPassword()?>"/></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><input type="button" value="Modifica" onclick="javascript:modifica()" /></td>
                    </tr>
                    <tr>
                        <td id="result" style="visibility: hidden; color: green">Profilo modificato con successo.</td>
                    </tr>
                </table>
            </div>
        </center>
    </body>
</html>
